//
//  WAMainViewController.m
//  WeatherApp
//
//  Created by Julia on 7/25/14.
//  Copyright (c) 2014 Yuliya Grasevych. All rights reserved.
//

#import "WAWeatherViewController.h"
#import "WAWeatherView.h"
#import "WACustomCollectionView.h"
#import "WAAddCityViewController.h"
#import "AppDelegate.h"
#import "WAWeatherProvider.h"

#import "NSView+FillWithView.h"

@interface WAWeatherViewController () <NSCollectionViewDelegate>

@property (nonatomic) WAWeatherView *weatherView;
@property (weak) IBOutlet WACustomCollectionView *collectionView;
@property (nonatomic) NSWindowController *addCityWindowController;
@property (weak) IBOutlet NSButton *addCityButton;
- (IBAction)addCity:(id)sender;
- (IBAction)previousCity:(id)sender;
- (IBAction)nextCity:(id)sender;

@end

@implementation WAWeatherViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

-(void)awakeFromNib
{
    [super awakeFromNib];
    [self.view setWantsLayer:YES];
    [self.collectionView setMinItemSize:NSMakeSize(1010, 639)];
}
-(WAWeatherProvider *)provider
{
    [[WAWeatherProvider sharedInstance] addObserver:self.locationsController forKeyPath:@"locations" options:0 context:nil];
    return [WAWeatherProvider sharedInstance];
}
-(NSArray *)locations
{
    return [[WAWeatherProvider sharedInstance] locations];
}

#pragma mark - Actions
- (IBAction)addCity:(id)sender
{
    self.addCityWindowController = [[NSWindowController alloc] initWithWindowNibName:@"WAAddCityWindow"];
    [[(AppDelegate *)[NSApplication sharedApplication].delegate window] beginSheet:self.addCityWindowController.window completionHandler:nil];
   
}

- (IBAction)previousCity:(id)sender
{
    [self.collectionView scrollToPreviousItem];
}

- (IBAction)nextCity:(id)sender
{
    [self.collectionView scrollToNextItem];
}

@end
